{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9b5d9a93",
   "metadata": {},
   "source": [
    "----------\n",
    "* 2022/10/11/week08\n",
    "* python课堂笔记\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c205eab6",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "> 0. 代码的注释\n",
    "> 1. 用户输入\n",
    "> 2. 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29155418",
   "metadata": {},
   "source": [
    "## 0. 代码的注释\n",
    "\n",
    "> 1. #,一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61d87bcc",
   "metadata": {},
   "source": [
    "> 2.'''注释内容''' ，一般是注释代码块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec4f3a11",
   "metadata": {},
   "source": [
    "## 1.用户输入\n",
    "\n",
    "> 1. input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4af764e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "username:admin\n"
     ]
    }
   ],
   "source": [
    "username = input(\"username:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3ad0f838",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "password:123456\n"
     ]
    }
   ],
   "source": [
    "password = input(\"password:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4253a93a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账户:admin\n",
      "密码:123456\n",
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "username = input(\"账户:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "83a12ad7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:admin\n",
      "密码:123456\n",
      "欢迎admin登录!\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 迭代1:增加了判断功能\n",
    "# 假设我们数据库有用户信息：账号：admin，密码，123456\n",
    "user1 = \"admin\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "# 情景一：输入信息正确，登陆成功\n",
    "if user1 == username and password1 == password:\n",
    "    print(\"欢迎\"+user1+\"登录!\")\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "42255779",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:bkjhkj\n",
      "密码:ghkjhoil\n",
      "账号不存在或密码不正确\n",
      "您还有2次尝试的机会\n",
      "账号:hoi;jjk\n",
      "密码:khoi\n",
      "账号不存在或密码不正确\n",
      "您还有1次尝试的机会\n",
      "账号:uoijkm\n",
      "密码:joijl\n",
      "三次输入失败，请1小时候再来尝试\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 迭代2：增加循环功能\n",
    "# 假设我们数据库有用户信息：账号：admin，密码，123456\n",
    "user1 = \"admin\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1): # i是一个 int\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    # 情景一：输入信息正确，登陆成功\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登录!\")\n",
    "        break # 终止循环\n",
    "    # 情景二：账号不存在或密码不正确\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败，请1小时候再来尝试\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确\")\n",
    "            print(\"您还有\"+str(i-1)+\"次尝试的机会\") # str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5e390ab",
   "metadata": {},
   "source": [
    "## 2.格式化输出\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e6cada4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:wuyu\n",
      "age:18\n",
      "job:model\n",
      "salary:1000000000\n",
      "地区:深圳\n",
      "-------INFO OF-------wuyu---------\n",
      "age:18\n",
      "job:model\n",
      "salary:1000000000\n",
      "地区:深圳\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法一：字符串拼接\n",
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "reg = input(\"地区:\")\n",
    "\n",
    "info = '''-------INFO OF-------'''+ name +'''---------'''+'''\n",
    "age:'''+age+'''\n",
    "job:'''+job+'''\n",
    "salary:'''+salary+'''\n",
    "地区:'''+reg\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0042a4d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# input作为用户输入，其都以字符串形式返回\n",
    "age = input(\"age:\")\n",
    "print(age,type(age))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b6ca9144",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:wuyu\n",
      "age:18\n",
      "job:it\n",
      "salary:51215\n",
      "地区:深圳\n",
      "-------INFO OF wuyu-------\n",
      "age:18\n",
      "job:it\n",
      "salary:51215\n",
      "地区:深圳\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二：占位符%s str,依次有序输入\n",
    "name = input(\"name:\")\n",
    "age = int(input(\"age:\")) # 强制将str转换成int\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "reg = input(\"地区:\")\n",
    "\n",
    "info = info = '''-------INFO OF %s-------\n",
    "age:%d\n",
    "job:%s\n",
    "salary:%s\n",
    "地区:%s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e2657fa1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:zw\n",
      "age:18\n",
      "job:it\n",
      "salary:600065\n",
      "地区:广州\n",
      "-------INFO OF zw-------\n",
      "name:zw\n",
      "age:18\n",
      "job:it\n",
      "salary:600065\n",
      "地区:广州\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法三：format()格式化输出函数，参数传递，不需要考虑位置\n",
    "name = input(\"name:\")\n",
    "age = int(input(\"age:\")) # 强制将str转换成int\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "reg = input(\"地区:\")\n",
    "\n",
    "info = info = '''-------INFO OF {姓名}-------\n",
    "name:{姓名}\n",
    "age:{年龄}\n",
    "job:{工作}\n",
    "salary:{收入}\n",
    "地区:{地区}'''.format(年龄=age,姓名=name,工作=job,收入=salary,地区=reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "faa81029",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
